<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    <%@ page import="com.lp.cfg.ProConfig"%>
        <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
            <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
                <!DOCTYPE html>
                <html>

                <head>
                    <meta charset="UTF-8">
                    <title>
                        <%=ProConfig.PROJECT_NAME%>
                    </title>
                    <%@ include file="/WEB-INF/wechat/iot/common/resource_lib.jsp"%>
                        <script type="text/javascript" src="<%=basePath%>/lib/bigscreen/js/vue.min.js"></script>
                        <script type="text/javascript" src="<%=basePath%>/lib/element-ui/index.js"></script>
                        <link rel="stylesheet" type="text/css" href="<%=basePath%>/lib/element-ui/index.css" />
                        <style type="text/css">
                            body,
                            html {
                                height: 100%;
                                -webkit-tap-highlight-color: transparent;
                            }
                            
                            p.weui-tabbar__label {
                                color: #999 !important;
                            }
                            
                            .weui-tabbar__icon {
                                width: 24px;
                                height: 24px;
                            }
                            
                            .weui-tabbar__icon.active img.active {
                                display: block;
                            }
                            
                            .weui-tabbar__icon.active img {
                                display: none;
                            }
                            
                            .weui-tabbar__icon img {
                                display: block;
                            }
                            
                            .weui-tabbar__icon img.active {
                                display: none;
                            }
                            
                            .content-style {
                                background-color: white;
                                margin: 6px;
                                border-radius: 5px;
                                padding: 7px;
                            }
                            
                            .scene-title {
                                font-weight: 700;
                                color: #333;
                                font-size: 16px;
                                ;
                            }
                            
                            .scene-type {
                                display: inline-block;
                                width: 10px;
                                height: 10px;
                            }
                            
                            html,
                            body {
                                margin: 0;
                            }
                            
                            #app {
                                background-color: #ececee;
                                height: 100%;
                                width: 100%;
                                overflow: hidden;
                            }
                            
                            .addtrigger,
                            .alarm,
                            .messgae {
                                overflow: hidden;
                                position: absolute;
                                top: 0;
                                width: 100%;
                                height: 100%;
                                z-index: 1000;
                                transform: translateX(-100%);
                                transition: all 400ms cubic-bezier(.8, 0, .33, 1);
                                overflow-y: scroll;
                            }
                            
                            .addtrigger.nav-open,
                            .alarm.nav-open,
                            .messgae.nav-open {
                                transform: translateX(0px);
                                border-radius: 0% 0% 0% 0%;
                                background: #fff;
                            }
                            
                            .tabel-span {
                                color: rgb(156, 156, 156);
                                font-size: 13px;
                                margin-right: 8px;
                            }
                            
                            .demo-ruleForm {
                                margin: 10px 15px;
                            }
                            
                            .demo-alarm {
                                margin: 15px 45px 15px 30px;
                            }
                            
                            .add::-webkit-scrollbar {
                                display: none;
                            }
                            
                            .scrol {
                                overflow-y: scroll;
                                width: 100%;
                                height: 100%;
                            }
                            
                            .scrol::-webkit-scrollbar {
                                display: none;
                            }
                            
                            .el-checkbox {
                                margin: 0 2px;
                            }
                            
                            .el-checkbox.is-bordered+.el-checkbox.is-bordered {
                                margin: 5px 2px;
                            }
                            
                            .line {
                                line-height: 20px;
                            }
                            
                            .el-form-item__label {
                                padding-right: 5px;
                                margin: 0;
                                font-size: 13px;
                            }
                            
                            .el-message-box {
                                width: 80%;
                                padding-bottom: 0;
                            }
                            
                            .el-message-box__btns {
                                padding: 5px 0 0;
                                text-align: center;
                            }
                            
                            .el-button--small {
                                width: 48%;
                                height: 34px;
                            }
                            
                            .el-message-box__header {
                                padding-bottom: 0;
                            }
                            
                            .weui-navbar-a {
                                font-size: 13px;
                                width: 50%;
                                line-height: 30px;
                                text-align: center;
                            }
                            
                            .weui-navbar {
                                border-bottom: 1px solid #d9d9d9;
                                padding-bottom: 5px;
                                padding-top: 7px;
                                height: 35px;
                                width: 100%;
                                margin: 0;
                            }
                            
                            .weui-tab-a {
                                background-color: #0d72c8;
                            }
                            
                            .weui-tab-a a {
                                color: #FFF;
                            }
                            
                            .weui_tab_bd_item {
                                display: none;
                            }
                            
                            .weui_tab_bd_item_active {
                                display: block;
                            }
                            
                            .label {
                                margin: 0 20px 10px;
                                font-size: 15px;
                            }
                            
                            .name {
                                margin: 50px 0 30px;
                                text-align: center;
                                font-size: 18px;
                            }
                            
                            .tabel-span1 {
                                color: rgb(156, 156, 156);
                                font-size: 14px;
                                margin: 0 0 5px 7px;
                            }
                        </style>
                </head>

                <body>
                    <div class="weui-tab">
                        <div class="body-container" style="height: 100%; overflow: auto;">
                            <div id="app">
                                <!-- 顶部选择框 -->
                                <!--<div class="weui-navbar">
                                    <div style="width:64%;height:30px;display:flex;margin:0 18%;border:1px solid #0d72c8;border-radius: 20px;">
                                        <div style="width:100%;height:100%;border-radius: 20px 0 0 20px;color:#0d72c8;" @click="nabtab(1)" class="weui-navbar-a weui-tab-a" id="tab1">
                                            <a>触发器列表</a>
                                        </div>
                                        <div style="width:100%;height:100%;border-radius: 0 20px 20px 0;color:#0d72c8;" @click="nabtab(2)" class="weui-navbar-a" id="tab2">
                                            <a>报警联系人</a>
                                        </div>
                                    </div>
                                </div> -->
                                <!-- 内容 -->
                                <div style="width: 100%;margin-top: 5px;margin-bottom: 50px;display: flex;" id="content">
                                    <!-- 触发器列表 -->
									<!-- <div id="tab3" style="margin-top:50px;"> -->
                                    <div id="tab3" >
                                       <!-- <div style="height: 40px;display: flex;margin: 0px 5px  7px;">-->
                                            <el-select v-model="alarm" @change="alarmstap" style="width: 98%;margin: 0px 1% 7px 1%;">
                                                <el-option v-for="scene in scenelist" :label="scene.name" :value="scene.id"></el-option>
                                            </el-select>
										 <!--</div><div style="height: 40px;display: flex;margin: 0px 5px  7px;">-->
                                            <el-select v-model="node" placeholder="Please select device" @change="nodetap" style="width: 80%;margin: 0px 1% 7px 1%;">
                                                <el-option label="Please select" value=""></el-option>
                                                <el-option v-for="item in nodelist" :label="item.name" :value="item.id"></el-option>
                                            </el-select>
                                            <el-button type="primary" icon="el-icon-plus" style="height: 40px;width: 16%;" @click="addTrigger"></el-button>
                                       <!-- </div>-->
                                        <div class="scrol">
                                            <div style="display: flex;justify-content: space-between;margin:0 0 5px;background-color: #fff;padding: 10px 13px;" v-for="(tab,index) in tabel">
                                                <div @click="tabeltap(tab)" style="width: 67%;">
                                                    <div style="font-size: 17px;"><span class="tabel-span">Name:</span>{{tab.name}}</div>
                                                    <div style="margin-top: 3px;"><span class="tabel-span">Correlation sensor:</span><span style="font-size: 13.5px;color: rgb(255, 102, 0);">{{tab.from_sensor_name}}</span></div>
                                                    <div style="margin-top: 3px;"><span class="tabel-span">Trigger condition:</span><span style="font-size: 13.5px;color: rgb(99, 98, 98);">{{tab.iot_trigger_condition_type}}</span></div>
                                                    <div style="display: flex;margin-top: 3px;">
                                                        <div style="margin-right: 15px;"><span class="tabel-span">argument:</span><span style="font-size: 13.5px;color: rgb(102, 102, 102);">{{tab.condition_params}}</span></div>
                                                        <div><span class="tabel-span">status:</span><span style="font-size: 13.5px;color: rgb(134, 110, 241);">{{tab.iot_trigger_status == 44?'Pause':'Normal'}}</span></div>
                                                    </div>
                                                </div>
                                                <div style="display: flex;margin: auto 0;width: auto;">
                                                    <el-button type="primary" icon="el-icon-edit" @click="edit(tab)"></el-button>
                                                    <el-button type="danger" icon="el-icon-delete" @click="del(tab,index)"></el-button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- 联系人列表 -->
                                    <div id="tab4" style="display: none;margin-top:50px;width:100%;">
                                        <div style="height:100%;width:100%;">
                                            <div style="height: 38px;display: flex;margin: 0px 5px 7px;">
                                                <!-- <el-select v-model="alarm" @change="alarms" style="width: 41%;margin-right: 1%;">
                                                        <el-option :label="item.name" v-for="item in scenelist" :value="item.id"></el-option>
                                                    </el-select>
                                                    <el-select v-model="node" placeholder="请选择设备" @change="nodetap" style="width: 41%;margin-right: 1%;">
                                                        <el-option :label="item.name" v-for="item in nodelist" :value="item.id"></el-option>
                                                    </el-select> -->
                                                <el-button type="primary" style="height: 38px;width: 80%;margin: 0 10%;" @click="addAlarm">Add a contact</el-button>
                                            </div>
                                            <div class="scrol">
                                                <!-- <div style="display: flex;justify-content: space-between;margin: 0 0 5px;background-color: #fff;padding: 10px 15px;">
                                                    <div>
                                                        <div><span class="tabel-span">姓名:</span><span style="font-size: 15px;"></span></div>
                                                        <div style="margin-top: 3px;"><span class="tabel-span">电话:</span><span style="font-size: 14px;color: rgb(50, 50, 50);"></span></div>
                                                        <div style="margin-top: 3px;"><span class="tabel-span">邮箱:</span><span style="font-size: 14px;color: rgb(100, 100, 100);"></span></div>
                                                        <div style="display: flex;margin-top: 3px;">
                                                            <div style="margin-right: 30px;"><span class="tabel-span">新增时间:</span><span style="font-size: 14px;color: rgb(114, 114, 114);"></span></div>
                                                        </div>
                                                    </div>
                                                    <div style="display: flex;margin: auto 0;">
                                                        <el-button type="primary" icon="el-icon-edit" @click="editAlarm(tab)"></el-button>
                                                        <el-button type="danger" icon="el-icon-delete" @click="delAlarm(tab)"></el-button>
                                                    </div>
                                                </div> -->
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- 新增联系人的页面 -->
                                <div class="alarm">
                                    <div style="margin: 120px 0 30px;text-align: center;font-size: 18px;">Add a contact</div>
                                    <el-form :model="alarms" :rules="rulesalarm" ref="alarms" label-width="50px" class="demo-alarm">
                                        <el-form-item label="Name" prop="name">
                                            <el-input v-model="alarms.name" placeholder="Please fill in your name"></el-input>
                                        </el-form-item>
                                        <el-form-item label="sex" prop="gender">
                                            <el-select v-model="alarms.gender" placeholder="Please select gender">
                                                <el-option label="male" value="0"></el-option>
                                                <el-option label="female" value="1"></el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="telephone" prop="phone">
                                            <el-input v-model="alarms.phone" type="tel" placeholder="Please fill in the phone number"></el-input>
                                        </el-form-item>
                                        <el-form-item label="Email" prop="email">
                                            <el-input v-model="alarms.email" type="email" placeholder="Please fill in the email"></el-input>
                                        </el-form-item>
                                        <div style="margin: 0 15% 20px;">
                                            <el-button type="primary" @click="submit(alarms)">submit</el-button>
                                            <el-button type="info" @click="cancel" style="margin-left: 50px;">Cancel</el-button>
                                        </div>
                                    </el-form>
                                </div>
                                <!-- 新增触发器的页面 -->
                                <div class="addtrigger">
                                    <div style="margin: 25px 0;text-align: center;font-size: 18px;">{{name}}</div>
                                    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="95px" class="demo-ruleForm">
                                        <el-form-item label="Trigger name" prop="name">
                                            <el-input v-model="ruleForm.name" placeholder="Enter the trigger name"></el-input>
                                        </el-form-item>
                                        <el-form-item label="Device" prop="node_id">
                                            <el-select v-model="ruleForm.node_id" @change="formNode" placeholder="Please select device">
                                                <el-option :label="item.name" v-for="item in nodelist" :value="item.id"></el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="Sensor" prop="from_sensor_id">
                                            <el-select v-model="ruleForm.from_sensor_id" placeholder="Please select sensor">
                                                <el-option v-for="srlt in sersorlist" :label="srlt.name" :value="srlt.id"></el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="Trigger type" prop="iot_trigger_condition_type">
                                            <el-select v-model="ruleForm.iot_trigger_condition_type" @change="fromTypes" placeholder="Please select a trigger type">
                                                <el-option v-for="tps in typetable" :label="tps.name" :value="tps.id"></el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="X" v-show="showX">
                                            <el-input v-model="condition_paramsX" type="number" style="width: 89%;" placeholder="X"></el-input>
                                        </el-form-item>
                                        <el-form-item label="Y" v-show="showY">
                                            <el-input v-model="condition_paramsY" type="number" style="width: 89%;" placeholder="Y"></el-input>
                                        </el-form-item>
                                        <el-form-item label="M" v-show="showM">
                                            <el-input v-model="condition_paramsM" type="number" style="width: 89%;" placeholder="M"></el-input>
                                        </el-form-item>
                                        <el-form-item label="Action type">
                                            <el-checkbox-group v-model="type">
                                                <el-checkbox v-for="list in labellist" :label="list.id" @change="checkb(list)" :value="list.id" border>{{list.name}}</el-checkbox>
                                            </el-checkbox-group>
                                        </el-form-item>
                                        <div v-show="control">
                                            <el-form-item label="Control device">
                                                <el-select v-model="controls" placeholder="Joint control device">
                                                    <el-option v-for="con in controlList" :label="con.sensorName" :value="con.sensorId"></el-option>
                                                </el-select>
                                            </el-form-item>
                                            <el-form-item label="Device action">
                                                <el-select v-model="action">
                                                    <el-option v-for="act in actionList" :label="act.name" :value="act.id"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </div>
                                        <el-form-item label="Contact information" v-show="contact">
                                            <el-select v-model="contts" placeholder="Fill in the contact information">
                                                <el-option v-for="contacts in contacts" :label="contacts.name" :value="contacts.id"></el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="Message" prop="iot_trigger_alarm_flag">
                                            <el-select v-model="ruleForm.iot_trigger_alarm_flag" @change="alarmFlag">
                                                <el-option v-for="act in actionList" :label="act.name" :value="act.id"></el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="Interval[s]" class="line" prop="trigger_inteval_time">
                                            <el-input v-model="ruleForm.trigger_inteval_time" type="number" placeholder="0 does not loop trigger"></el-input>
                                        </el-form-item>
                                        <el-form-item label="Enable or not">
                                            <el-select v-model="ruleForm.iot_trigger_status">
                                                <el-option v-for="status in statusList" :label="status.name" :value="status.id"></el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="Alarm level" v-show="alarm_level">
                                            <el-select v-model="ruleForm.iot_trigger_alarm_level">
                                                <el-option v-for="level in levelList" :label="level.name" :value="level.id"></el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="Recovery" prop="recovery">
                                            <el-select v-model="ruleForm.recovery">
                                                <el-option v-for="act in actionList" :label="act.name" :value="act.id"></el-option>
                                            </el-select>
                                        </el-form-item>
                                        <div style="margin: 0 15% 20px;">
                                            <el-button type="primary" @click="submitForm(ruleForm)">submit</el-button>
                                            <el-button type="info" @click="canceladd" style="margin-left: 50px;">Cancel</el-button>
                                        </div>
                                    </el-form>
                                </div>
                                <!-- 触发器信息页面 -->
                                <div class="messgae" style="display: flex;flex-direction: column;">
                                    <div class="name">Trigger information</div>
                                    <div class="label">
                                        <span class="tabel-span1">Name：</span>
                                        <span>{{editFrom.name}}</span>
                                    </div>
                                    <div class="label">
                                        <span class="tabel-span1">Devce：</span>
                                        <span>{{editFrom.node_name}}</span>
                                    </div>
                                    <div class="label">
                                        <span class="tabel-span1">Sensor：</span>
                                        <span>{{editFrom.from_sensor_name}}</span>
                                    </div>
                                    <div class="label">
                                        <span class="tabel-span1">Trigger condition type：</span>
                                        <span>{{editFrom.condition_type}}</span>
                                    </div>
                                    <div class="label">
                                        <span class="tabel-span1">argument：</span>
                                        <span>{{editFrom.condition_params}}</span>
                                    </div>
                                    <div class="label">
                                        <span class="tabel-span1">Execution type：</span>
                                        <span>{{editFrom.type}}</span>
                                    </div>
                                    <div v-show="control">
                                        <div class="label">
                                            <span class="tabel-span1">Joint control equipment：</span>
                                            <span>{{editFrom.controls}}</span>
                                        </div>
                                        <div class="label">
                                            <span class="tabel-span1">Joint control device action：</span>
                                            <span>{{editFrom.action_level}}</span>
                                        </div>
                                    </div>
                                    <div class="label" v-show="contact">
                                        <span class="tabel-span1">Contact person：</span>
                                        <span>{{editFrom.contact}}</span>
                                    </div>
                                    <div class="label">
                                        <span class="tabel-span1">Generate alarm message：</span>
                                        <span>{{editFrom.alarm_flag}}</span>
                                    </div>
                                    <div class="label">
                                        <span class="tabel-span1">Cycle interval：</span>
                                        <span>{{editFrom.trigger_inteval_time}}</span>
                                    </div>
                                    <div class="label">
                                        <span class="tabel-span1">Enable or not：</span>
                                        <span>{{editFrom.status}}</span>
                                    </div>
                                    <div class="label">
                                        <span class="tabel-span1">Alarm level：</span>
                                        <span>{{editFrom.alarm_level}}</span>
                                    </div>
                                    <div class="label">
                                        <span class="tabel-span1">Alarm recovery trigger：</span>
                                        <span>{{editFrom.recovery_level}}</span>
                                    </div>
                                    <el-button type="primary" style="margin: auto;" @click="error()">confirm</el-button>
                                </div>
                            </div>
                        </div>
                        <%@ include file="/WEB-INF/wechat/iot/moudle/operate.jsp"%>
                    </div>
                    <script>
                        var app = new Vue({
                            el: '#app',
                            data() {
                                return {
                                    // 新增触发器信息
                                    ruleForm: {
                                        name: '',
                                        node_id: '',
                                        from_sensor_id: 0,
                                        trigger_inteval_time: '',
                                        iot_trigger_condition_type: '',
                                        iot_trigger_alarm_level: 39,
                                        recovery: 36,
                                        iot_trigger_alarm_flag: 37,
                                        iot_trigger_status: 43,
                                        condition_params: ''
                                    },
                                    action: 36,
                                    controls: '',
                                    contts:'',
                                    condition_paramsX: '',
                                    condition_paramsY: '',
                                    condition_paramsM: '',
                                    type: [],
                                    editFrom: {},
                                    baseHead: 'lpro/service',
                                    // 联系人信息
                                    alarms: {
                                        name: '',
                                        phone: '',
                                        gender: '',
                                        email: ''
                                    },
                                    // 动作类型
                                    labellist: [],
                                    actionList: [],
                                    statusList: [],
                                    levelList: [],
                                    controlList: [],
                                    contacts:[],
                                    alarm: '',
                                    name: 'Add trigger',
                                    node: '',
                                    showX: false,
                                    showY: false,
                                    showM: false,
                                    control: false,
                                    contact: false,
                                    alarm_level: false,
                                    nodelist: [],
                                    scenelist: [],
                                    sceneId: '',
                                    nodeId: '',
                                    edittrigger: 100,
                                    tabel: [],
                                    sersorlist: [],
                                    // 触发类型
                                    typetable: [],
                                    // 新增联系人的验证
                                    rulesalarm: {
                                        name: [{
                                            required: true,
                                            message: 'Please enter your name',
                                            trigger: 'blur'
                                        }],
                                        gender: [{
                                            required: true,
                                            message: 'Please select gender',
                                            trigger: 'change'
                                        }],
                                        email: [{
                                            required: true,
                                            message: 'Please enter your email address',
                                            trigger: 'blur'
                                        }, {
                                            type: 'email',
                                            message: 'Please enter the correct email address',
                                            trigger: ['blur', 'change'],
                                        }, ],
                                        phone: [{
                                            required: true,
                                            message: 'Please enter your phone number',
                                            trigger: 'blur'
                                        }, {
                                            pattern: /^(1[3584]\d{9})$/,
                                            message: 'Please enter the correct mobile number',
                                        }, ]
                                    },
                                    // 新增触发器的验证
                                    rules: {
                                        name: [{
                                            required: true,
                                            message: 'Please enter a trigger name',
                                            trigger: 'blur'
                                        }, {
                                            min: 2,
                                            max: 8,
                                            message: 'The length is 2 to 8 characters',
                                            trigger: 'blur'
                                        }],
                                        trigger_inteval_time: [{
                                            required: true,
                                            message: 'Cannot be empty',
                                            trigger: 'blur'
                                        }],
                                        node_id: [{
                                            required: true,
                                            message: 'Please select device',
                                            trigger: 'change'
                                        }],
                                        from_sensor_id: [{
                                            required: true,
                                            message: 'Please select sensor',
                                            trigger: 'change'
                                        }],
                                        iot_trigger_condition_type: [{
                                            required: true,
                                            message: 'Please select a trigger type',
                                            trigger: 'change'
                                        }],
                                        iot_trigger_alarm_flag: [{
                                            required: true,
                                            message: 'Please select Generate alarm message',
                                            trigger: 'change'
                                        }],
                                        recovery: [{
                                            required: true,
                                            message: 'Please select alarm recovery trigger',
                                            trigger: 'change'
                                        }]
                                    }
                                }
                            },
                            methods: {
                                // 获取各种下拉框数据
                                getArray() {
                                    var that = this

                                    function getSelect(id) {
                                        //获取下拉框数据的请求
                                        $.ajax({
                                            type: "get",
                                            url: localUrl + "/api/dictionary/getDictionariesByPCode/" + id,
                                            dataType: "json",
                                            success: function(res) {
                                                // 这是请求成功
                                                if (id == 28) {
                                                    that.typetable = res.dictionaries
                                                } else if (id == 49) {
                                                    that.labellist = res.dictionaries
                                                } else if (id == 35) {
                                                    that.actionList = res.dictionaries
                                                } else if (id == 42) {
                                                    that.statusList = res.dictionaries
                                                } else if (id == 38) {
                                                    that.levelList = res.dictionaries
                                                }
                                            },
                                            error: function(err) {

                                            }
                                        });
                                    }
                                    //获取联系人
                                    $.ajax({
                                        type: "get",
                                        url: localUrl + "/api/contact/getContacts",
                                        dataType: "json",
                                        success: function(res) {
                                            // 这是请求成功
                                            if(res.status == 1){
                                            	that.contacts = res.contacts
                                            }
                                        },
                                        error: function(err) {

                                        }
                                    });
                                    //获取触发类型数据
                                    function gettypes() {
                                        getSelect(28)
                                    }
                                    //获取动作类型数据
                                    function getlabellist() {
                                        getSelect(49)
                                    }
                                    //获取联控设备动作数据
                                    function getaction() {
                                        getSelect(35)
                                    }
                                    //获取是否开启的数据
                                    function getstatus() {
                                        getSelect(42)
                                    }
                                    //获取报警级别数据
                                    function getlevel() {
                                        getSelect(38)
                                    }
                                    // commonAjax('post', localUrl + "/createTask", {}, function(data) {
                                    //     if (data == 200) {

                                    //     }
                                    //     if (data == 501) {

                                    //     }
                                    // })
                                    getlevel()
                                    getstatus()
                                    getaction()
                                    getlabellist()
                                    gettypes()
                                },
                                //展示报警级别
                                alarmFlag(key) {
                                    if (key == 36) {
                                        this.alarm_level = true
                                    } else {
                                        this.alarm_level = false
                                    }
                                },
                                // 新增联系人
                                addAlarm() {
                                    var app = document.querySelector('.alarm')
                                    app.classList.toggle('nav-open');
                                },
                                //保存新增联系人
                                submit(alarm) {
                                    var app = document.querySelector('.alarm')
                                    app.classList.toggle('nav-open');
                                },
                                // 取消新增联系人
                                cancel() {
                                    this.addAlarm()
                                    this.alarms = {
                                        name: '',
                                        phone: '',
                                        gender: '',
                                        email: ''
                                    }
                                },
                                // 修改联系人
                                editAlarm(alarm) {
                                    var app = document.querySelector('.alarm')
                                    app.classList.toggle('nav-open');
                                },
                                //删除联系人
                                delAlarm(alarm) {

                                },
                                // 切换触发器列表和联系人列表
                                nabtab(index) {
                                    if (index == 1) {
                                        var aretap = document.getElementById('tab1')
                                        aretap.classList.add('weui-tab-a');
                                        var tab2 = document.getElementById('tab2')
                                        tab2.classList.remove('weui-tab-a');
                                        var tab3 = document.getElementById('tab3')
                                        tab3.style.display = 'block';
                                        var tab4 = document.getElementById('tab4')
                                        tab4.style.display = 'none';
                                    } else {
                                        var aretap = document.getElementById('tab2')
                                        aretap.classList.add('weui-tab-a');
                                        var tab2 = document.getElementById('tab1')
                                        tab2.classList.remove('weui-tab-a');
                                        var tab3 = document.getElementById('tab4')
                                        tab3.style.display = 'block';
                                        var tab4 = document.getElementById('tab3')
                                        tab4.style.display = 'none';
                                    }
                                },
                                //查看触发器
                                tabeltap(item) {
                                    var that = this
                                    var app = document.querySelector('.messgae')
                                    app.classList.toggle('nav-open');
                                    $.ajax({
                                        type: "get",
                                        url: localUrl + "/api/trigger/getTrigger/" + item.id,
                                        dataType: "json",
                                        success: function(res) {
                                            // 这是请求成功
                                            if (res.status == 1) {
                                                that.editFrom = res.trigger
                                                for (let i = 0, len = that.levelList.length; i < len; i++) {
                                                    if (that.editFrom.iot_trigger_alarm_level == that.levelList[i].id) {
                                                        that.editFrom.alarm_level = that.levelList[i].name
                                                    }
                                                }
                                                for (let i = 0, lth = that.typetable.length; i < lth; i++) {
                                                    if (that.editFrom.iot_trigger_condition_type == that.typetable[i].id) {
                                                        that.editFrom.condition_type = that.typetable[i].name
                                                    }
                                                }
                                                for (let j = 0, le = that.statusList.length; j < le; j++) {
                                                    if (that.editFrom.iot_trigger_status == that.statusList[j].id) {
                                                        that.editFrom.status = that.statusList[j].name
                                                    }
                                                }
                                                for (let h = 0, leng = that.actionList.length; h < leng; h++) {
                                                    if (that.editFrom.recovery == that.actionList[h].id) {
                                                        that.editFrom.recovery_level = that.actionList[h].name
                                                    }
                                                    if (that.editFrom.iot_trigger_alarm_flag == that.actionList[h].id) {
                                                        that.editFrom.alarm_flag = that.actionList[h].name
                                                    }
                                                }
                                                that.editFrom.iot_trigger_action_type = that.editFrom.iot_trigger_action_type.split(',')
                                                if (that.editFrom.iot_trigger_action_type.length > 1) {
                                                    that.contact = true
                                                    for (var i = 0, len = that.editFrom.iot_trigger_action_type.length; i < len; i++) {
                                                        if (that.editFrom.iot_trigger_action_type[i] == '50') {
                                                            that.control = true
                                                        }
                                                    }
                                                } else if (that.editFrom.iot_trigger_action_type.length == 1) {
                                                    if (that.editFrom.iot_trigger_action_type[0] == '50') {
                                                        that.control = true
                                                        that.contact = false
                                                    } else {
                                                        that.control = false
                                                        that.contact = true
                                                    }
                                                } else {
                                                    that.contact = false
                                                    that.control = false
                                                }
                                                that.editFrom.type = ''
                                                for (let t = 0, lt = that.labellist.length; t < lt; t++) {
                                                    for (let l = 0, lh = that.editFrom.iot_trigger_action_type.length; lh > l; l++) {
                                                        if (that.editFrom.iot_trigger_action_type[l] == that.labellist[t].id) {
                                                            that.editFrom.type += that.labellist[t].name + ','
                                                        }
                                                    }
                                                }
                                                that.editFrom.type = that.editFrom.type.substring(0, that.editFrom.type.length - 1)
                                                that.editFrom.action_params = jQuery.parseJSON(that.editFrom.action_params)
                                                that.editFrom.action_level = that.editFrom.action_params.control_device_status
                                                that.editFrom.controls = that.editFrom.action_params.control_device
                                                that.editFrom.contact = that.editFrom.action_params.contactor
                                                for (let j = 0, le = that.controlList.length; j < le; j++) {
                                                    if (that.editFrom.controls == that.controlList[j].sensorId) {
                                                        that.editFrom.controls = that.controlList[j].sensorName
                                                    }
                                                }
                                                for (let i = 0, len = that.actionList.length; i < len; i++) {
                                                    if (that.actionList[i].id == that.editFrom.action_level) {
                                                        that.editFrom.action_level = that.actionList[i].name
                                                    }
                                                }
                                                that.formNode(that.editFrom.node_id)
                                                for (let i = 0, len = that.nodelist.length; i < len; i++) {
                                                    if (that.nodelist[i].id == that.editFrom.node_id) {
                                                        that.editFrom.node_name = that.nodelist[i].name
                                                    }
                                                }
                                            }
                                        },
                                        error: function(err) {

                                        }
                                    });
                                },
                                //返回触发器
                                error() {
                                    var app = document.querySelector('.messgae')
                                    app.classList.toggle('nav-open');
                                },
                                //删除触发器
                                del(form, index) {
                                    var that = this
                                    commonAjax('put', localUrl + "/api/trigger/del/" + form.id, {}, function(data) {
                                        console.log(data)
                                        if (data.status == 2) {
                                            alert('Successfully deleted！')
                                            that.tabel.splice(index,  1);
                                            that.$set(that.tabel);
                                        }
                                        if (data.status == 1) {
                                            alert("Deletion failure！");
                                            that.getTabel(that.sceneId, '')
                                        }
                                    })
                                },
                                //修改触发器
                                edit(form) {
                                    var that = this
                                    that.formNode(form.node_id,form.id)
                                    that.edittrigger = 200
                                    that.name = "Modify trigger"
                                    var app = document.querySelector('.addtrigger')
                                    app.classList.toggle('nav-open');
                                },
                                // 新增触发器的传感器选择
                                formNode(key,id) {
                                    var that = this
                                    $.ajax({
                                        type: "get",
                                        url: localUrl + "/api/sensor/getSensors/" + key + '/'+25,
                                        dataType: "json",
                                        success: function(res) {
                                            // 这是请求成功
                                            if (res.status == 1) {
                                                that.sersorlist = res.sensors
                                                that.getSwtich(key,id)
                                            }
                                        },
                                        error: function(err) {

                                        }
                                    });
                                },
                                getSwtich(key,id){
                                    var that = this
                                	that.ruleForm.from_sensor_id = ''
                                	$.ajax({
                                        type: "get",
                                        //'/api/sensor/getSensors/{nodeId}/{sensorType}'
                                        url: localUrl + "/api/sensor/getSensors/" + key + '/'+27,
                                        dataType: "json",
                                        success: function(res) {
                                            // 这是请求成功
                                            if (res.status == 1) {
                                                that.sersorlist =  that.sersorlist.concat(res.sensors)
                                                that.getFrom(id)
                                                /* for (let i = 0, len = that.sersorlist.length; i < len; i++) {
                                                    if (that.sersorlist[i].id == that.editFrom.from_sensor_id) {
                                                        that.editFrom.from_sensor_name = that.sersorlist[i].name
                                                    }
                                                } */
                                            }
                                        },
                                        error: function(err) {

                                        }
                                    });
                                    },
                                getFrom(id) {
                                    var that = this
                                    $.ajax({
                                        type: "get",
                                        url: localUrl + "/api/trigger/getTrigger/" + id,
                                        dataType: "json",
                                        success: function(res) {
                                            // 这是请求成功
                                            that.ruleForm = res.trigger
                                            that.type = that.ruleForm.iot_trigger_action_type.split(',')
                                            that.ruleForm.condition_params = that.ruleForm.condition_params.split(',')
                                            if (that.ruleForm.iot_trigger_condition_type == 33 || that.ruleForm.iot_trigger_condition_type == 34 || that.ruleForm.iot_trigger_condition_type == 31 || that.ruleForm.iot_trigger_condition_type == 189) {
                                                that.condition_paramsX = that.ruleForm.condition_params[0]
                                                if (that.ruleForm.iot_trigger_condition_type == 31 || that.ruleForm.iot_trigger_condition_type == 189) {
                                                    that.condition_paramsY = that.ruleForm.condition_params[1]
                                                } else if (that.ruleForm.iot_trigger_condition_type == 33 || that.ruleForm.iot_trigger_condition_type == 34) {
                                                    that.condition_paramsM = that.ruleForm.condition_params[1]
                                                }
                                            } else if (that.ruleForm.iot_trigger_condition_type == 29 || that.ruleForm.iot_trigger_condition_type == 32) {
                                                that.condition_paramsX = that.ruleForm.condition_params[0]
                                            } else if (that.ruleForm.iot_trigger_condition_type == 30) {
                                                that.condition_paramsY = that.ruleForm.condition_params[0]
                                            } else if (that.ruleForm.iot_trigger_condition_type == 280) {
                                                that.condition_paramsM = that.ruleForm.condition_params[0]
                                            }

                                            if (that.ruleForm.iot_trigger_condition_type != 30 && that.ruleForm.iot_trigger_condition_type != 280) {
                                                that.showX = true
                                            } else {
                                                that.showX = false
                                            }

                                            if (that.ruleForm.iot_trigger_condition_type == 30 || that.ruleForm.iot_trigger_condition_type == 31 || that.ruleForm.iot_trigger_condition_type == 189) {
                                                that.showY = true
                                            } else {
                                                that.showY = false
                                            }

                                            if (that.ruleForm.iot_trigger_condition_type == 33 || that.ruleForm.iot_trigger_condition_type == 34 || that.ruleForm.iot_trigger_condition_type == 280) {
                                                that.showM = true
                                            } else {
                                                that.showM = false
                                            }

                                            if (that.type.length > 1) {
                                                that.contact = true
                                                for (var i = 0, len = that.type.length; i < len; i++) {
                                                    if (that.type[i] == '50') {
                                                        that.control = true
                                                    }
                                                }
                                            } else if (that.type.length == 1) {
                                                if (that.type[0] == '50') {
                                                    that.control = true
                                                    that.contact = false
                                                } else {
                                                    that.control = false
                                                    that.contact = true
                                                }
                                            } else {
                                                that.contact = false
                                                that.control = false
                                            }
                                            for (let m = 0, lh = that.labellist.length; lh > m; m++) {
                                                that.labellist[m].id = String(that.labellist[m].id)
                                            }
                                            that.ruleForm.action_params = jQuery.parseJSON(that.ruleForm.action_params)
                                            that.ruleForm.action = that.ruleForm.action_params.control_device_status
                                            that.controls = that.ruleForm.action_params.control_device
                                            that.contts = that.ruleForm.action_params.contactor
                                                // for (let i = 0, len = that.controlList.length; i < len; i++) {
                                                //     if (that.controlList[i].id == that.ruleForm.controls) {
                                                //         that.ruleForm.controls = that.controlList[i].name
                                                //     }
                                                // }
                                        },
                                        error: function(err) {

                                        }
                                    });
                                },
                                //取消新增触发器
                                canceladd() {
                                    var that = this
                                    var app = document.querySelector('.addtrigger')
                                    app.classList.toggle('nav-open');
                                },
                                // 保存新增触发器
                                submitForm(from) {
                                    console.log(from)
                                    var that = this
                                    let types = that.type.toString()
                                    if (that.condition_paramsX == '' && that.condition_paramsY == '' && that.condition_paramsM != '') {
                                        from.condition_params = that.condition_paramsM
                                    }
                                    if (that.condition_paramsX == '' && that.condition_paramsM == '' && that.condition_paramsY != '') {
                                        from.condition_params = that.condition_paramsY
                                    }
                                    if (that.condition_paramsX != '' && that.condition_paramsY != '' && that.condition_paramsM == '') {
                                        from.condition_params = that.condition_paramsX + ',' + that.condition_paramsY
                                    }
                                    if (that.condition_paramsX != '' && that.condition_paramsM != '' && that.condition_paramsY == '') {
                                        from.condition_params = that.condition_paramsX + ',' + that.condition_paramsM
                                    }
                                    if (that.condition_paramsX != '' && that.condition_paramsM == '' && that.condition_paramsY == '') {
                                        from.condition_params = that.condition_paramsX
                                    }
                                    var tmp = {
                                        'control_device': that.controls,
                                        "control_device_status": that.action,
                                        "contactor": that.contts
                                    }
                                    from.condition_params = from.condition_params.toString()
                                    console.log(from.condition_params)
                                    var action_params = JSON.stringify(tmp)
                                    if (that.edittrigger == 100) {
                                        commonAjax('post', localUrl + "/api/trigger/add", {
                                            'action_params': action_params,
                                            'condition_params': from.condition_params,
                                            'from_sensor_id': from.from_sensor_id,
                                            'iot_trigger_action_type': types,
                                            'iot_trigger_alarm_flag': from.iot_trigger_alarm_flag,
                                            'iot_trigger_alarm_level': from.iot_trigger_alarm_level,
                                            'iot_trigger_condition_type': from.iot_trigger_condition_type,
                                            'iot_trigger_status': from.iot_trigger_status,
                                            'name': from.name,
                                            'node_id': from.node_id,
                                            'recovery': from.recovery,
                                            'trigger_inteval_time': from.trigger_inteval_time,
                                        }, function(data) {
                                            if (data.status == 2) {
                                                var app = document.querySelector('.addtrigger')
                                                app.classList.toggle('nav-open');
                                                that.getTabel(that.sceneId, '')
                                            }
                                            if (data.status == 1) {

                                            }
                                        })
                                    } else {
                                        commonAjax('put', localUrl + "/api/trigger/update", {
                                            'action_params': action_params,
                                            'condition_params': from.condition_params,
                                            'from_sensor_id': from.from_sensor_id,
                                            'id': from.id,
                                            'iot_trigger_action_type': types,
                                            'iot_trigger_alarm_flag': from.iot_trigger_alarm_flag,
                                            'iot_trigger_alarm_level': from.iot_trigger_alarm_level,
                                            'iot_trigger_condition_type': from.iot_trigger_condition_type,
                                            'iot_trigger_status': from.iot_trigger_status,
                                            'name': from.name,
                                            'node_id': from.node_id,
                                            'recovery': from.recovery,
                                            'trigger_inteval_time': from.trigger_inteval_time,
                                        }, function(data) {
                                            if (data.status == 2) {
                                                var app = document.querySelector('.addtrigger')
                                                app.classList.toggle('nav-open');
                                                that.getTabel(that.sceneId, '')
                                            }
                                            if (data.status == 1) {

                                            }
                                        })
                                    }

                                },
                                //新建触发器
                                addTrigger() {
                                    var that = this
                                    that.edittrigger = 100
                                    var app = document.querySelector('.addtrigger')
                                    app.classList.toggle('nav-open');
                                    that.ruleForm = {
                                        name: '',
                                        node_id: '',
                                        from_sensor_id: '',
                                        trigger_inteval_time: '',
                                        iot_trigger_condition_type: '',
                                        iot_trigger_alarm_level: 39,
                                        recovery: 36,
                                        iot_trigger_alarm_flag: 37,
                                        action: 36,
                                        controls: '',
                                        contact: '',
                                        iot_trigger_status: 43,
                                        condition_params: ''
                                    }
                                    that.condition_paramsX = '',
                                        that.condition_paramsY = '',
                                        that.condition_paramsM = '',
                                        that.type = []
                                    this.showX = false
                                    this.showY = false
                                    this.showM = false
                                    this.alarm_level = false
                                    this.contact = false
                                    this.control = false
                                },
                                //触发类型选择框
                                fromTypes(key) {
                                    if (key != 30 && key != 280) {
                                        this.showX = true
                                    } else {
                                        this.showX = false
                                    }
                                    if (key == 30 || key == 31 || key == 189) {
                                        this.showY = true
                                    } else {
                                        this.showY = false
                                    }
                                    if (key == 33 || key == 34 || key == 280) {
                                        this.showM = true
                                    } else {
                                        this.showM = false
                                    }
                                },
                                // 项目下拉框
                                alarmstap(key) {
                                    console.log(key)
                                    var id = ''
                                    this.node = ''
                                    this.sceneId = key
                                    this.getNode(key)
                                    this.getTabel(key, id)
                                },
                                // 设备下拉框
                                nodetap(key) {
                                    console.log(key)
                                    this.getTabel(this.sceneId, key)
                                },
                                // 动作类型多选
                                checkb(key) {
                                    this.$set(this.type)
                                    if (this.type.length > 1) {
                                        this.contact = true
                                        for (var i = 0, len = this.type.length; i < len; i++) {
                                            if (this.type[i] == '50') {
                                                this.control = true
                                                return
                                            }
                                        }
                                        this.control = false
                                    } else if (this.type.length == 1) {
                                        if (this.type[0] == '50') {
                                            this.control = true
                                            this.contact = false
                                        } else {
                                            this.control = false
                                            this.contact = true
                                        }
                                    } else {
                                        this.contact = false
                                        this.control = false
                                    }
                                },
                                //获取设备列表
                                getNode(id) {
                                    var that = this
                                    $.ajax({
                                        type: "get",
                                        url: localUrl + "/api/node/getNodes/" + id,
                                        dataType: "json",
                                        success: function(res) {
                                            // 这是请求成功
                                            if (res.status == 1) {
                                                that.nodelist = res.nodes
                                            }
                                        },
                                        error: function(err) {

                                        }
                                    });
                                },
                                // 获取设备组
                                getScene() {
                                    var that = this
                                    var id = ''
                                    $.ajax({
                                        type: "get",
                                        url: localUrl + "/api/scene/getScenes",
                                        dataType: "json",
                                        success: function(res) {
                                            // 这是请求成功
                                            if (res.status == 1) {
                                                that.scenelist = res.scenes
                                                that.sceneId = res.scenes[0].id
                                                that.getNdeSensor(res.scenes[0].id)
                                                that.getNode(res.scenes[0].id)
                                                that.alarm = res.scenes[0].id

                                            }
                                        },
                                        error: function(err) {

                                        }
                                    });
                                },
                                getNdeSensor(Id) {
                                    var that = this
                                    var id = ''
                                    $.ajax({
                                        type: "get",
                                        url: localUrl + "/api/sensor/getNodeSensorBySceneId/" + Id,
                                        dataType: "json",
                                        success: function(res) {
                                            // 这是请求成功
                                            that.controlList = res.nodeSensor
                                            that.getTabel(that.sceneId, id)
                                        },
                                        error: function(err) {

                                        }
                                    });
                                },
                                //获取触发器列表数据
                                getTabel(sceneId, nodeid) {
                                    var that = this
                                    if (nodeid == '') {
                                        $.ajax({
                                            type: "get",
                                            url: localUrl + "/api/trigger/getTriggers/" + sceneId,
                                            dataType: "json",
                                            success: function(res) {
                                                // 这是请求成功)
                                                that.tabel = res.triggers
                                                for (let i = 0, len = that.tabel.length; len > i; i++) {
                                                    for (let j = 0, leng = that.typetable.length; leng > j; j++) {
                                                        if (that.tabel[i].iot_trigger_condition_type == that.typetable[j].id) {
                                                            that.tabel[i].iot_trigger_condition_type = that.typetable[j].name
                                                        }
                                                    }
                                                    /* for (let h = 0, lt = that.controlList.length; lt > h; h++) {
                                                        if (that.tabel[i].from_sensor_id == that.controlList[h].sensorId) {
                                                            that.tabel[i].from_sensor_name = that.controlList[h].sensorName
                                                        }
                                                    } */
                                                }
                                            },
                                            error: function(err) {

                                            }
                                        });
                                    } else {
                                        $.ajax({
                                            type: "get",
                                            url: localUrl + "/api/trigger/getTriggers/" + sceneId + '/' + nodeid,
                                            dataType: "json",
                                            success: function(res) {
                                                // 这是请求成功
                                                that.tabel = res.triggers
                                                for (let i = 0, len = that.tabel.length; len > i; i++) {
                                                    for (let j = 0, leng = that.typetable.length; leng > j; j++) {
                                                        if (that.tabel[i].iot_trigger_condition_type == that.typetable[j].id) {
                                                            that.tabel[i].iot_trigger_condition_type = that.typetable[j].name
                                                        }
                                                    }
                                                    /* for (let h = 0, lt = that.controlList.length; lt > h; h++) {
                                                        if (that.tabel[i].from_sensor_id == that.controlList[h].sensorId) {
                                                            that.tabel[i].from_sensor_name = that.controlList[h].sensorName
                                                        }
                                                    } */
                                                }
                                            },
                                            error: function(err) {

                                            }
                                        });
                                    }

                                },
                                //获取联系人列表数据
                                getalarm() {
                                    $.ajax({
                                        type: "get",
                                        url: "/api/scene/getScene",
                                        dataType: "json",
                                        success: function(res) {
                                            // 这是请求成功
                                            if (res.data.status == 200) {
                                                data = res.data.data
                                                this.getNode(res.data.data[i].id)
                                            }
                                        },
                                        error: function(err) {

                                        }
                                    });
                                }
                            },
                            mounted() {
                                this.getScene()
                                this.getArray()
                                document.getElementById('content').style.height = (document.documentElement.clientHeight - 100) + 'px'
                            }
                        })
                    </script>
                </body>
                <script type="text/javascript">
                    $(".weui-tabbar .weui-tabbar__icon").eq(2).addClass("active");
                </script>

                </html>